package com.lesso.cyg.sunflower.domain.service;

import com.baomidou.mybatisplus.plugins.Page;
import com.lesso.cyg.sunflower.domain.repository.EmployeeDeviceRelRepository;
import com.lesso.cyg.sunflower.infra.assembler.EmployeeDeviceRelAssembler;
import com.lesso.cyg.sunflower.pojo.dto.EmployeeDeviceRelDTO;
import com.lesso.cyg.sunflower.pojo.dto.EmployeeDeviceRelQueryDTO;
import com.lesso.cyg.sunflower.model.EmployeeDeviceRel;
import org.springframework.stereotype.Service;

/**
 * EmployeeDeviceRelDomainService
 *
 * @author cyg
 * @since 2025-07-02
 */
@Service
public class EmployeeDeviceRelDomainService {

    private final EmployeeDeviceRelRepository employeeDeviceRelRepository;

    public EmployeeDeviceRelDomainService(EmployeeDeviceRelRepository employeeDeviceRelRepository) {
        this.employeeDeviceRelRepository = employeeDeviceRelRepository;
    }

    public Integer save(EmployeeDeviceRelDTO dto) {
        return employeeDeviceRelRepository.save(EmployeeDeviceRelAssembler.INSTANCE.dtoToEntity(dto));
    }

    public void deleteById(Long id) {
        employeeDeviceRelRepository.removeById(id);
    }

    public Integer update(EmployeeDeviceRelDTO dto) {
        return employeeDeviceRelRepository.update(EmployeeDeviceRelAssembler.INSTANCE.dtoToEntity(dto));
    }

    public Page<EmployeeDeviceRelDTO> page(EmployeeDeviceRelQueryDTO dto) {
        // 这里需要实现具体的查询逻辑，根据 dto 中的条件查询
        Page<EmployeeDeviceRel> entityPage = new Page<>(dto.getPage().getCurrent(), dto.getPage().getSize());
        Page<EmployeeDeviceRelDTO> dtoPage = new Page<>();
        dtoPage.setRecords(EmployeeDeviceRelAssembler.INSTANCE.entityListToDtoList(entityPage.getRecords()));
        return dtoPage;
    }
}